layui.define(['table', 'form','my_send'], function(exports){
    var $ = layui.$
    ,table = layui.table
    ,form = layui.form
    ,http_proxy = layui.http_proxy;
    //车站故障统计
    table.render({
      elem: '#LAY-AnalysisOfAlarmData'
      , url: http_proxy('/alarm/allLineStationFaultStatistics') //模拟接口
      ,parseData:function(res){
        return{
          "code":0
          ,"count":''
          ,"data":res.data
          ,'msg':''
        }
      }
      ,cols: [[
        {field: 'id', title: '序号', width: 60}
        ,{field: 'station', title: '车站'}
        ,{field: 'deviceNum', title: '故障设备数'}
        ,{field: 'deviceSumNum', title: '设备总数'}
      ]]
      ,page: false
      ,limit: 10
      ,limits: [10, 15, 20, 25, 30]
      ,text: '暂无数据'
    });
     //实时报警
     $.ajax({
      type : "get",
      async : false, //异步执行
      url : http_proxy("/alarm/getDropDownBox"),
      dataType : "json", //返回数据形式为json
      success : function(data) {
        $.each(data.data.systems,function(index,item){
          $('#alarmSystems').append(new Option(item,index));
        })
        $.each(data.data.stations,function(index,item){
          $('#alarmStations').append(new Option(item,index));
        })
        $.each(data.data.levels,function(index,item){
          $('#alarmLevels').append(new Option(item,index));
        })
        form.render('select');
       
      },
      error : function(errorMsg) {
        alert("请求数据失败");
      }
    });
      
     table.render({
        elem: '#LAY-realTimeAlerts'
         ,url: http_proxy('/alarm/allLineRealAlarm')
         ,id:'LAY-realTimeAlerts'
         ,parseData:function(res){
             return{
                 "code":0
                 ,"count":''
                 ,"data":res.data
                 ,'msg':''
             }
         }
        ,cols: [[
          {field: 'alarmTime',title: '报警生产时间'}
          ,{field: 'alarmStation', title: '车站'}
          ,{field: 'alarmDevice', title: '系统'}
          ,{field: 'rank', title: '优先级'}
          ,{field: 'alarmStatus', title: '状态'}
          ,{field: 'alarmMessage', title: '报警描述'}
          ,{field: 'alarmValue', title: '数值'}
          ,{field: 'recoveryTime', title: '恢复时间'}
        ]]
         ,page: true
         ,limit: 10
         ,limits: [10, 15, 20, 25, 30]
         ,text: {
             none:'暂无数据'
         }
      });
      //搜索角色
      form.on('submit(LAY-user-front-search)', function (data) {
        debugger
        //执行重载
        table.reload('LAY-realTimeAlerts', {
          where: data.field
        });
      });


 // 重要设备故障统计TOP10
 $.ajax({
    type : "get",
    async : false, //异步执行
    url: http_proxy('/alarm/stationAlarmTop'), //模拟接口
    dataType : "json", //返回数据形式为json
    success : function(data) {
      stationAlarmTop = data.data;
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
  });
  //各专业故障统计
  var dataList=[];
  var dataValueList=new Array();
  $.ajax({
    type : "get",
    async : false, //异步执行
    url: http_proxy('/alarm/indexGetAlarmByType'),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      alarmGradingStation = data.data;
      for(var i=0;i< alarmGradingStation.length;i++){
        dataList.push( alarmGradingStation[i].name);
        var map= new Map;
        map.name= alarmGradingStation[i].name;
        map.value= alarmGradingStation[i].value;
        dataValueList.push(map);
      }
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
  });
  // 各级别故障统计
    var dataListFault=[];
    var dataValueListFault=new Array();
    $.ajax({
        type : "get",
        async : false, //异步执行
        url: http_proxy('/alarm/faultStatisticsAllLevels'),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            faultStatisticsAllLevels = data.data;
            for(var i=0;i< faultStatisticsAllLevels.length;i++){
                dataListFault.push( faultStatisticsAllLevels[i].name);
                var map= new Map;
                map.name= faultStatisticsAllLevels[i].name;
                map.value= faultStatisticsAllLevels[i].value;
                dataValueListFault.push(map);
            }
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
// 重要设备故障统计TOP10
  var stationAlarm = echarts.init(document.getElementById('stationAlarm0'));
  var option;
  option = {
    title: {
      textStyle: {
        color: '#606266',
      },
    },
    tooltip: {},
    grid:{
        height:'66%',
    },
    xAxis: [{
        axisLabel:{
            interval: 0,
            rotate:40,
            textStyle: {  //这里设置X轴字体样式
                color: '#606266',
            }
        },
        axisLine:{       //这里设置X轴样式
            lineStyle:{
                color:'#606266',
                width:1,                  
            },
        },
        axisTick: {
          alignWithLabel: true
        },
      data:stationAlarmTop.xData,
    }],
    yAxis: {
        name: "单位:%",
        axisLabel: {    //这里设置Y轴字体样式
            show: true,  
            interval: 'auto',  
            formatter: '{value}',
            textStyle: {
            color: '#606266',
            fontSize: '70%',
            },
        },
        axisLine:{       //这里设置Y轴样式
            lineStyle:{
                color:'#606266',
                width:1,                  
            }
        }
    },
    series: [{
      type: 'bar',
      barWidth: '50%',
      data:stationAlarmTop.yData
    }]
  };
  stationAlarm.setOption(option);
//各专业故障统计
  var stationAlarm = echarts.init(document.getElementById('stationAlarm1'));
  option = {
    tooltip: {
    //   show: true,
      trigger: 'item',
      formatter: "{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'horizontal',
        x: 'left',
        textStyle: {
            color: '#606266',
        },
        // data:['AFC','ATS','PSD','ACS','FAS']
        data:dataList
    },
    series: [
      {
        type:'pie',
        radius: ['50%', '70%'],
        avoidLabelOverlap: false,
        // color: ["#AF89D6", "#5ab6df", "#6a8bc0", "#4acacb", "#fe8676"],
        label: {
            normal: {
                show: false,
                position: 'center',
                formatter:this.echartsBLable,
                textStyle:{
                  fontSize:30,
                  color:'#FFDF25'
                }
            },
            emphasis: {
                show: true,
                textStyle: {
                    fontSize: '30',
                    fontWeight: 'bold'
                }
            }
        },
        labelLine: {
            normal: {
                show: false
            }
        },
        data:dataValueList
      },
    ]
};
  stationAlarm.setOption(option);

  var stationAlarm = echarts.init(document.getElementById('stationAlarm2'));
  option = {
    tooltip : {
        trigger: 'item',
        formatter: "{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'horizontal',
        left: 'left',
        textStyle: {
            color: '#606266',
        },
        data:dataListFault
    },
    series : [
        {
            type:'pie',
            radius : '70%',
            center: ['50%', '50%'],
            data:dataValueListFault,
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            },
        }
    ]
};
  stationAlarm.setOption(option);
    exports('dataAnalysis', {})
  });